# https://www.geeksforgeeks.org/sieve-of-eratosthenes/

def SieveOfEratosthenes(n):
    # Create a boolean array "prime[0..n]" and initialize all entries it as true.
    # A value in prime[i] will finally be false if i is Not a prime, else true.
    prime = [True for i in range(n + 1)]
    p = 2
    while p * p <= n:
        # If prime[p] is not changed, then it is a prime
        if prime[p]:
            # Update all multiples of p
            for i in range(p * p, n + 1, p):
                prime[i] = False
        p += 1

    # Print all prime numbers
    return [p for p in range(2, n + 1) if prime[p]]


prime_nums = SieveOfEratosthenes(1000)

print(prime_nums)

twin_primes = []

for i in range(0, len(prime_nums)-1, 1):
    if prime_nums[i+1] - prime_nums[i] == 2:
        twin_primes.append((prime_nums[i], prime_nums[i+1]))
        # print("({},{})".format(prime_nums[i], prime_nums[j]))

print(twin_primes)
